<%--
  Created by IntelliJ IDEA.
  User: 123
  Date: 2020/11/17
  Time: 17:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <form id="s">
        用户名:<input type="text" name="username" id="d"/><br>
        密码:<input type="text" name="password" id="c"/></br>
        <button type="button" onclick="doAjax()">登录</button>
    </form>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.serializejson.js"></script>
<script type="text/javascript">
    function doAjax() {
        var d= JSON.stringify($("#s").serializeJSON())
       console.log(d)
        $.ajax({
            url:"${pageContext.request.contextPath}/Users",
            contentType:"application/json",
            data:d,
            dataType:"json",
            type:"POST",
            success:function (date) {
                console.log(date.code)
                if (date.code=="success"){
                    location="index.jsp"
                }
            }
        })
    }
</script>
</body>
</html>
